home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / MSDOS / (m)aak / UNCRUNCH.ASM < prev    next >
Assembly Source File  |  1987-06-20  |  7KB  |  180 lines

  1. ;This is the flash display routine used to display crunched TheDraw image
  2. ;files.  It uses a custom protocol for reproducing a image with any
  3. ;possible color combinations.  The control codes below 32 are reserved
  4. ;for this function.  The following data structure shows the format of a
  5. ;sequence.  Not all operations use the optional bytes <x> or <y>..
  6. ;
  7. ;Data Structure:  <current byte>[<x>[<y>]]
  8. ;
  9. ;   0..15 = New Foreground Color
  10. ;  16..23 = New Background Color
  11. ;      24 = Go down to next line, return to same horizontal position as when
  12. ;           routine was started (akin to a c/r).
  13. ;      25 = Displays <x> number of spaces.
  14. ;      26 = Displays <x> number of <y>.  Also used to display ANY characters
  15. ;           below #32.  This function is the only way to do this although it
  16. ;           uses three bytes.  Otherwise the code would be interpreted as
  17. ;           another command.
  18. ;
  19. ;----------------------------------------------------------------------------
  20. ;
  21. ;To use this routine you call the procedure with the ImageData pointed to
  22. ;by the DS:SI register pair and the display address pointed to by the ES:DI
  23. ;register pair.  The length of the ImageData must be in the CX register.
  24. ;All used registers are stored on the stack are restore after use.
  25. ;
  26. ;Assume we have a ImageData file of a 40 characters by 10 lines block.  Also
  27. ;the following defintions.  ie:
  28. ;
  29. ;
  30. ;     ;TheDraw Crunched Asm...etc...Length=467
  31. ;     ImageData  DB      ...list of image bytes here...
  32. ;
  33. ;                MOV     SI,offset ImageData
  34. ;                MOV     AX,0B800H
  35. ;                MOV     ES,AX
  36. ;                MOV     DI,34*2 + 5*160-162
  37. ;                MOV     CX,467
  38. ;                CALL    UNCRUNCH
  39. ;
  40. ;It is assume DS points to the segment ImageData resides in.  The above
  41. ;Sets up the ES:DI pair to point to position (34,5) on the screen, calculated
  42. ;as an offset from the start of the screen.
  43. ;
  44. ;The value of 467 used is the length of the array as indicated by the title
  45. ;block provided by TheDraw.
  46. ;
  47. ;UnCrunch remembers the horizontal (X) starting position when it goes down
  48. ;to the next line.  This allows you to display the ImageData block correctly
  49. ;at any position on the screen.   ie:
  50. ;
  51. ;  +-------------------------------------------------+
  52. ;  |                                                 |
  53. ;  |                                                 | <- Pretend this
  54. ;  |                                                 |    is the video
  55. ;  |           ┌─────────────────────┐               |    display.
  56. ;  |           │█████████████████████│               |
  57. ;  |           │█████████████████████│               |
  58. ;  |           │██ ImageData block ██│               |
  59. ;  |           │█████████████████████│               |
  60. ;  |           │█████████████████████│               |
  61. ;  |           │█████████████████████│               |
  62. ;  |           └─────────────────────┘               |
  63. ;  |                                                 |
  64. ;  |                                                 |
  65. ;  |                                                 |
  66. ;  +-------------------------------------------------+
  67. ;
  68. ;
  69. ;The ImageData block could just as well have been display in the upper-left
  70. ;corner of the screen with:
  71. ;                MOV     SI,offset ImageData
  72. ;                MOV     AX,0B800H
  73. ;                MOV     ES,AX
  74. ;                MOV     DI,1*2 + 1*160-162
  75. ;                MOV     CX,467
  76. ;                CALL    UNCRUNCH
  77. ;
  78. ;Notice the offset address changed to the coordinates (1,1).
  79. ;
  80. ;To display the block in the lower-right corner you would change the MOV DI,
  81. ;statement to:
  82. ;                MOV     DI,40*2 + 15*160-162
  83. ;
  84. ;The block is 40 characters wide by 10 lines deep.  Therefore to display
  85. ;such a large block, we must display the block at coordinate (40,15);
  86. ;
  87. ;
  88. ;Obviously I have been attempting to describe this procedure by use of
  89. ;examples.  This is done because I feel it is the easiest and clearest way
  90. ;of explaining this procedure.  It was designed to be as simple as possible,
  91. ;however for some people the best way to learn it is to experiment.  Try
  92. ;creating a program using the above example information.  Use TheDraw to
  93. ;make a 40 by 10 block (or any size) to experiment with.  Good luck.  If
  94. ;you can devise a better way of explaining this, please share your labors
  95. ;with me.   Others will surely benifit.   Thanks!
  96. ;
  97.  
  98.  
  99. UNCRUNCH PROC NEAR
  100. ;
  101. ;Parameters Required:
  102. ;  DS:SI  ImageData source pointer.
  103. ;  ES:DI  Display address pointer.
  104. ;  CX     Length of ImageData source data.
  105. ;
  106.        PUSH    SI                      ;Save registers.
  107.        PUSH    DI
  108.        PUSH    AX
  109.        PUSH    CX
  110.        PUSH    DX
  111.  
  112.        MOV     DX,DI                   ;Save X coordinate for later.
  113.        XOR     AX,AX                   ;Set Current attributes.
  114.  
  115. LOOPA: LODSB                           ;Get next character.
  116.        CMP     AL,16                   ;If less than 16, then change the
  117.        JNC     BackGround              ;foreground color.  Otherwise jump.
  118.        AND     AH,0F0H
  119.        OR      AH,AL
  120.        JMP     Short Next
  121.  
  122. BackGround:
  123.        CMP     AL,24                   ;If less than 24, then change the
  124.        JZ      NextLine                ;background color.  If exactly 24,
  125.        JNC     MultiOutput             ;then jump down to next line.
  126.        SUB     AL,16                   ;Otherwise jump to multiple output
  127.        ADD     AL,AL                   ;routines.
  128.        ADD     AL,AL
  129.        ADD     AL,AL
  130.        ADD     AL,AL
  131.        AND     AH,0FH
  132.        OR      AH,AL
  133.        JMP     Short Next
  134.  
  135. NextLine:
  136.        ADD     DX,160                  ;If equal to 24,
  137.        MOV     DI,DX                   ;then jump down to
  138.        JMP     Short Next              ;the next line.
  139.  
  140. MultiOutput:
  141.        CMP     AL,25                   ;If equal to 25,
  142.        JNZ     NotMultiSpaces          ;then using the
  143.        LODSB                           ;following code as
  144.        PUSH    CX                      ;a count, output
  145.        XOR     CH,CH                   ;said number of
  146.        MOV     CL,AL                   ;spaces.
  147.        MOV     AL,32
  148.        JMP     StartOutput             ;Use below loop.
  149.  
  150. NotMultiSpaces:
  151.        CMP     AL,26                   ;If equal to 26, then using
  152.        JNZ     NormalLetter            ;the following two codes, display
  153.        LODSB                           ;<x> number of <y> characters.
  154.        DEC     CX                      ;Adjust main counter.
  155.        PUSH    CX                      ;Display as many of
  156.        XOR     CH,CH                   ;whatever the user
  157.        MOV     CL,AL                   ;wants.
  158.        LODSB                           ;Get character.
  159.  
  160. StartOutput:
  161.        JCXZ    Stop                    ;Abort if already at zilch.
  162. LOOPB: STOSW
  163.        LOOP    LOOPB
  164. Stop:  POP     CX
  165.        DEC     CX                      ;Adjust main counter.
  166.  
  167. NormalLetter:
  168.        STOSW                           ;Save screen letter.
  169.  
  170. Next:  JCXZ    Done                    ;Get next, unless CX
  171.        LOOP    LOOPA                   ;has already one to zero.
  172.  
  173. Done:  POP     DX                      ;Restore registers.
  174.        POP     CX
  175.        POP     AX
  176.        POP     DI
  177.        POP     SI
  178.        RET
  179.  
  180. UNCRUNCH ENDP